import {AzraelFrameWorkComponent} from "../Base/AzraelFrameWork";
import ccclass = cc._decorator.ccclass;
import {IUIForm} from "../../src/UI/IUIForm";
import GameFrameworkModule from "../../src/Base/GameFrameworkModule";
import {IUIManager} from "../../src/UI/IUIManager";
import GameFrameworkEntry from "../../src/Base/GameFrameworkEntry";
import {UIManager} from "../../src/UI/UIManager";
import ResourceManager from "../../src/Resources/ResourceManager";
import property = cc._decorator.property;

@ccclass
export class UIComponent extends AzraelFrameWorkComponent{

    private _UIManager: IUIManager & GameFrameworkModule = null;

    @property(cc.String)
    private UIFormHelperName:string = "UIFromDefaultHelper";
    @property(cc.String)
    private resourcepath:string = "";
    private _canvas:cc.Canvas;
    public getCanvas():cc.Canvas{
        return this._canvas;
    }

    protected onLoad(): void {
        super.onLoad();
        this._UIManager = GameFrameworkEntry.GetModule(UIManager);
        this._UIManager.SetResourceManager(GameFrameworkEntry.GetModule(ResourceManager));
        let defaulthelper = this.getComponent(this.UIFormHelperName);
        this._UIManager.SetUIFormHelper(defaulthelper);
        this._canvas = cc.find("GameFramework/UI/Canvas").getComponent(cc.Canvas);
    }

    Init(serialIds:Map<number,string>){
        this._UIManager.init(serialIds,this.resourcepath);
    }

    HasUIForm(serialId: number): boolean{
        return this._UIManager.HasUIForm(serialId);
    }

    GetUIForm(serialId: number): IUIForm{
        return this._UIManager.GetUIForm(serialId);
    }
    GetAllLoadedUIForms(): IUIForm[]{
        return this._UIManager.GetAllLoadedUIForms();
    }

    OpenUIForm(serialId:number,userdata?):number{
        return this._UIManager.OpenUIForm(serialId,userdata);
    }

    CloseUIForm(serialId:number|IUIForm,userdata?):void{
        this._UIManager.CloseUIForm(serialId,userdata);
    }
    GetCurrentUIForm():IUIForm{
        return this._UIManager.GetCurrentUIForm();
    }
}